// 云函数入口文件
const cloud = require('wx-server-sdk')

cloud.init({ env: cloud.DYNAMIC_CURRENT_ENV }) // 使用当前云环境

// 云函数入口函数
exports.main = async (event, context) => {
  return cloud.callFunction({
    name: "model_address",
    data: {
      op: "update",
      id: event.address_id,
      u_id: event.u_id,
      content: event.content,
      default: event.default,
      address_name: event.address_name,
      address_phone: event.address_phone
    }
  }).then(res => {
    if (res.result.stats.updated == 1) {
      return cloud.callFunction({
        name: "model_address",
        data: {
          op: "select",
          key: "_id",
          value: event.address_id
        }
      }).then(res => { return res.result.data; })
    } else {
      return "0"
    }
  })
}